﻿@model LoginViewModel
@using NewLife.Common;
@{
    Layout = null;
    ViewBag.Title = "登录";

    var res = Model.ResourceUrl;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - @SysConfig.Current.DisplayName</title>

    <link href="@res/elementui/css/element.css" rel="stylesheet" />
    <link href="@res/elementui/css/layout.css" rel="stylesheet" />
    <style>
        html {
            background-color: #f2f2f2;
        }

        form {
            width: 350px;
            margin: auto;
            margin-top: 50px;
        }

            form button {
                width: 100%;
            }

        .logo {
            text-align: center;
            margin: 50px auto;
            font-size: 30px;
        }
        .login-container {
            width: 100%;
            height: 100%;
        }

        .login-page {
            -webkit-border-radius: 5px;
            border-radius: 5px;
            margin: 180px auto;
            width: 350px;
            padding: 35px 35px 15px;
            background: #fff;
            border: 1px solid #eaeaea;
            box-shadow: 0 0 25px #cac6c6;
        }

        label.el-checkbox.rememberme {
            margin: 0px 0px 15px;
            text-align: left;
        }
    </style>
</head>

<body>

    <template id="app">
        <div class="login-container">
            <el-form :model="loginform" 
                     status-icon
                     :rules="rules" 
                     ref="loginform"
                     label-position="left"
                     label-width="0px"
                     class="demo-ruleForm login-page">
                <h3 class="title">@ViewBag.Title - @SysConfig.Current.DisplayName</h3>
                <el-form-item prop="username">
                    <el-input type="text"
                              v-model="loginform.userName"
                              auto-complete="off"
                              placeholder="用户名"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input type="password"
                              v-model="loginform.password"
                              auto-complete="off"
                              placeholder="密码"></el-input>
                </el-form-item>
                <el-checkbox v-model="loginform.remember"
                             class="rememberme">记住密码</el-checkbox>
                <el-form-item style="width:100%;">
                    <el-button type="primary" style="width:100%;" @@click="submitForm('loginform')" :loading="loading">登录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </template>

    <!-- ElementUI -->
    <script src="@res/elementui/js/moment.min.js"></script>
    <script src="@res/elementui/js/axios.min.js"></script>
    <script src="@res/elementui/js/vue.min.js"></script>
    <script src="@res/elementui/js/element.min.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                loading: false,
                loginform: {
                    userName: null,
                    password: null,
                    remember: false

                },
                rules: {
                    userName: [
                        { required: true, message: '请输入用户名' },
                        { min: 3, max: 32, message: '长度在 3 到 32 个字符' }
                    ],
                    password: [
                        { required: true, message: '请输入密码' },
                        { min: 3, max: 32, message: '长度在 3 到 32 个字符' }
                    ],
                }
            },
            methods: {
                submitForm(formName) {
                    let self = this;
                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                            self.loading = true;
                            axios.post("login", self.loginform)
                                .then(function (rsp) {
                                    if (rsp.data.code == 0) {
                                        location.href = "../";
                                    } else {
                                        self.$message.error(rsp.data.info);
                                    }
                                    self.loading = false;
                                }).catch((error) => {
                                    console.log(error);
                                    if (error.request || error.response) {
                                        self.$message.error('系统错误');
                                    }
                                    self.loading = false;
                                });
                        } else {
                            console.log('error submit!!');
                            return false;
                        }
                    });
                },
            }
        });
    </script>
</body>

</html>